﻿namespace JoelAbrahamsson.WebUtilities
{
    public static class StringExtensions
    {
        public static string EllipseText(this string text, int maxLength)
        {
            if (text.Length > maxLength)
                return text.Substring(0, maxLength) + "...";
            return text;
        }

        public static string GetMD5Hash(this string text)
        {
            System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] bs = System.Text.Encoding.UTF8.GetBytes(text);
            bs = x.ComputeHash(bs);
            System.Text.StringBuilder s = new System.Text.StringBuilder();
            foreach (byte b in bs)
            {
                s.Append(b.ToString("x2").ToLower());
            }
            string password = s.ToString();
            return password;
        }
    }
}
